CHARTS

Beach Volleyball

Heat Map

Photo by Mike Cox on Unsplash

Photo by Mike Cox on Unsplash

Economic growth doesn’t mean anything if it leaves people out…
— Jack Kemp


Load the data [Ingest]

# Load data
url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"
url_file <- "beach-volleyball/vb_matches.csv"
url <- paste0(url_root, url_file)

df <- read.csv(url, header = TRUE, stringsAsFactors = FALSE)
df

Prepare the data [Wrangle]

While creating a heatmap, it might make better sense to bin the continuous data into levels and represent each level as a discrete colour. The cut() function in R allows to break and label a continuous variable

vb <- df %>%
  # put all player countries into one column named "player_country"
  gather(c(w_p1_country, w_p2_country, 
           l_p1_country, l_p2_country),
         key="player", 
         value="player_country") %>%
  
  group_by(country, player_country)  %>%
  # count number of combos per country:player_country
  count() 
  
# Continous to Discrete Conversion
vb <- vb %>% drop_na() %>%
  ungroup() %>%
  mutate(ncolors=cut(n, breaks=c(0,10,25,50,75,100,125,150,175,200,1000,25000,50000,max(n)),
                      labels=c(10,25,50,75,100,125,150,175,200,1000,25000,50000,max(n)))) %>%
  mutate(ncolors = as.factor(ncolors))

Plot the chart

theme_opts <- theme(
    text = element_text(family = "inconsolata"), 
    plot.title = element_text(color = "black", size = 14, face = "bold"),
    plot.subtitle = element_text(color = "black", size = 12),
    plot.caption = element_text(color = "#555555", size = 8),
    axis.text.x=element_text(angle=90, hjust=1),
    axis.text = element_text(size=7.5),
    panel.border = element_blank(),
    panel.background = element_blank(),
    legend.title = element_text(color = "black", size = 8, face = "bold"), # remove legend title
    legend.text = element_text(color = "black", size = 8),
    legend.position='right'
)

colors <- c("#6e0000","#ff001c", "#e33044", "#de5023" ,"#f46d43","#faa14b" ,"#fdae61","#fee08b","#e6f598","#abdda4", "#a1e398","#ddf1da")


  
v1 <- ggplot(data = vb, aes(y=reorder(country,-n), 
           x=reorder(player_country,-n),
           fill=ncolors))+
  geom_tile(colour="white",size=0.15, alpha=0.8)+
  scale_fill_manual(values= rev(colors) ,na.value = "grey90") +
    labs(x="Player countries", y="Match location",
       color="Number of \ncombinations",size="Number of \ncombinations",
       title = "Where do beach volleyball players come from and where do they play?") +
  guides(fill=guide_legend(title="Occurances")) +
  theme_opts

girafe(ggobj = v1, width_svg = 16, height_svg = 9,
       options = list(opts_sizing(rescale = TRUE, width = 0.9)))

References

citations for narrative and data sources

  • Narrative sources: Tidy Tuesday, GO
  • Data sources: Big Time Stats, GO